

#ifndef __STATUS_THREAD_H
#define __STATUS_THREAD_H

class StatusThread
{
	HANDLE thread;

	bool  run;
public:

	StatusThread( )
		:	run(true) {

		Initialise();
	}

	virtual ~StatusThread() {

		CleanUp();
	}

	DWORD Go() {

		unsigned int lastFramesDecoded = VideoRAW::totalFramesDecoded;

		while(run)
		{
			unsigned int thisFramesDecoded = VideoRAW::totalFramesDecoded;
			unsigned int fps = 0;

			if(thisFramesDecoded >= lastFramesDecoded)
				fps = thisFramesDecoded - lastFramesDecoded;
			else
				fps = thisFramesDecoded + (0xffffffff - lastFramesDecoded); // wrapped around!

			cout << "working threads " << VideoRAW::inProgress << " fps " << fps << " total vids decoded " << VideoRAW::totalVideosDecoded << endl;

			lastFramesDecoded = thisFramesDecoded;

			Sleep(1000);
		}
		
		return 0;
	}

	static DWORD WINAPI ThreadMain(LPVOID lpParameter) {

		StatusThread *t = (StatusThread*)lpParameter;

		return t->Go();
	}

private:

	void Initialise() {

		thread = CreateThread(NULL,0, StatusThread::ThreadMain, (LPVOID)this, 0, 0);

	}

	void CleanUp() {

		run = false;

		WaitForSingleObject( thread, INFINITE );

		CloseHandle( thread );
	}
};


#endif /*** __STATUS_THREAD_H ***/

